package cn.swing.ui;

import lombok.Getter;
import javax.swing.*;
import java.awt.event.*;

/**
 * @author xbsoft2
 */
public final class Info extends JDialog {

  private JPanel contentPane;
  @Getter
  private JTextPane info;

  public Info(String text) {
    setContentPane(contentPane);
    setModal(true);
    setDefaultCloseOperation(DO_NOTHING_ON_CLOSE);
    addWindowListener(new WindowAdapter() {
        @Override
        public void windowClosing(WindowEvent e) {
          dispose();
        }
    });
    contentPane.registerKeyboardAction(e -> dispose(), KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);
    init(text);
  }
  private void init(String text) {
    info.setText(text);
    info.setBorder(null);
    this.setTitle("信息");
    this.setBounds(500,500,500,300);
    this.setVisible(Boolean.TRUE);
  }
}
